package org.ztr.yanai.ai.controller.chat;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/10/30 20:24
 * @Description: 测试ChatClient
 * @Version: 1.0
 */
@RestController
@RequestMapping("/ai")
public class ChatClientController {
    private final ChatClient dashScopeChatClient;

    /**
     * ChatClient不支持自动输入，依赖ChatModel对象接口，ChatClient.builder(dashScopeChatModel).build();
     *
     * @param dashScopeChatModel 模型
     */
    public ChatClientController(@Qualifier("dashscopeChatModel") ChatModel dashScopeChatModel) {
        this.dashScopeChatClient = ChatClient.builder(dashScopeChatModel).build();
    }

    @GetMapping("/chatclient/dochat")
    public String doChat(@RequestParam(name = "msg", defaultValue = "2加9等于几") String msg) {
        return dashScopeChatClient.prompt().user(msg).call().content();
    }
}

